package com.design;

/**
 * 测试类
 */
public class RedisTest {
    public static void main(String[] args) {
        CentralSubject redis=new CentralSubject();
        RealSubscriber zhangsan=new RealSubscriber("张三");
        RealSubscriber lisi=new RealSubscriber("李四");
        RealSubscriber wu=new RealSubscriber("王五");
        String channelName="sports";
        redis.addSubscriber(channelName,zhangsan);
        redis.addSubscriber(channelName,lisi);
        redis.addSubscriber(channelName,wu);
        System.out.println("当前订阅者数量:"+redis.getChannelSubject(channelName).getSubscriberCount());
        //发布消息
        System.out.println("发布消息-------------------");
        redis.publish(channelName,"今天是个好天气");
        //取消订阅
        System.out.println("退出订阅-------------------");
        redis.unsubscribe(channelName,zhangsan);
        System.out.println("当前订阅者数量:"+redis.getChannelSubject(channelName).getSubscriberCount());
        System.out.println("发布消息-------------------");
        redis.publish(channelName,"适合出去玩");
    }
}
